package logic

import (
	"cartRpc/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGoodsLogic {
	return &CreateGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateGoodsLogic) CreateGoods(req *types.CreateGoodsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	goods, err := l.svcCtx.CartRpc.CreateGoods(l.ctx, &cart.CreateGoodsRequest{
		Image:      req.Image,
		GoodsName:  req.GoodsName,
		GoodsPrice: float32(req.GoodsPrice),
		Stock:      req.Stock,
		ShopId:     req.ShopId,
		Status:     req.Status,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品发布成功",
		Code:    200,
		Data:    goods,
	}, nil
}
